Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add int4 & uint4 types to MigraphX #3378

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft

Conversation

lakhinderwalia
Copy link
Contributor

@lakhinderwalia lakhinderwalia commented Aug 15, 2024

Add int4 & uint4 types to MigraphX

@lakhinderwalia lakhinderwalia self-assigned this Aug 15, 2024
Copy link

codecov bot commented Aug 15, 2024

Codecov Report

Attention: Patch coverage is 37.50000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 92.24%. Comparing base (ae2b026) to head (45e0397).
Report is 2 commits behind head on develop.

Files Patch % Lines
src/shape.cpp 28.57% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3378      +/-   ##
===========================================
- Coverage    92.26%   92.24%   -0.02%     
===========================================
  Files          500      500              
  Lines        20057    20061       +4     
===========================================
  Hits         18506    18506              
- Misses        1551     1555       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES) tuple_type
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES) tuple_type,
uint4_type,
int4_type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a macro to list these types.

@@ -115,6 +115,9 @@ migraphx_shape_datatype_t to_shape_type(shape::type_t t)
case shape::x: return migraphx_shape_##x;
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT)
#undef MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT
case shape::uint4_type:
case shape::int4_type:
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wrong, the enum values should be exposed in the API and not throw an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@@ -381,6 +383,8 @@ struct MIGRAPHX_EXPORT shape
{
switch(t)
{
case uint4_type:
case int4_type:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tuple visitor should not be called for these types. It should throw an error.

src/shape.cpp Outdated
}

shape_impl(shape::type_t t, std::vector<std::size_t> l)
: m_type(t), m_lens(std::move(l)), m_standard(true)
{
assert(t != shape::tuple_type);
assert(t != shape::tuple_type && t != shape::uint4_type && t != shape::int4_type);
Copy link
Collaborator

@pfultz2 pfultz2 Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assert shouldn't be changed here. It should be valid to construct a shape of int4_type otherwise whats the point of adding this type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This one is definitely required.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant you are correct. This constructor code, as you suggest, is definitely required for correct functioning.
(I had just quickly hacked those places to make sure the CI would pass the compile stage -- as some switch statements etc. were failing.) Thanks.

src/shape.cpp Outdated
@@ -744,7 +752,7 @@ std::vector<shape> flatten(const std::vector<shape>& shapes)
auto subs = flatten(s.sub_shapes());
result.insert(result.end(), subs.begin(), subs.end());
}
else
else if(s.type() != shape::uint4_type && s.type() != shape::int4_type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be changed, we should still be able to flatten an tuples of int4_type.

@pfultz2
Copy link
Collaborator

pfultz2 commented Aug 15, 2024

In addition, we need to add unit tests for this type.

check_shapes needs to be updated to throw an error on these types with a flag to allow it for operators like unpack_int4, similar to the dynamic_allowed flag.

We also need a way to automatically insert the unpack_int4 for arguments in the onnx parser so we avoid passing it to unssuported operators(which is everything except unpack_int4).

I wont be around the next couple of weeks to help design or review this, so this will have to wait until september to tackle this further.

@lakhinderwalia lakhinderwalia changed the title Just to illustrate: add int4 & uint4 types Add int4 & uint4 types to MigraphX Aug 15, 2024
@pfultz2
Copy link
Collaborator

pfultz2 commented Aug 15, 2024

Also, we need update the bytes calculation to be the correct amount. We also need to throw when calling index calculations.

@migraphx-bot
Copy link
Collaborator

Test Batch Rate new
45e039
Rate old
ae2b02
Diff Compare
torchvision-resnet50 64 3,238.24 3,232.34 0.18%
torchvision-resnet50_fp16 64 6,883.75 6,875.78 0.12%
torchvision-densenet121 32 2,427.11 2,429.76 -0.11%
torchvision-densenet121_fp16 32 4,067.56 4,068.80 -0.03%
torchvision-inceptionv3 32 1,633.02 1,636.23 -0.20%
torchvision-inceptionv3_fp16 32 2,742.59 2,744.68 -0.08%
cadene-inceptionv4 16 771.06 771.82 -0.10%
cadene-resnext64x4 16 803.26 802.64 0.08%
slim-mobilenet 64 7,435.39 7,438.28 -0.04%
slim-nasnetalarge 64 207.39 207.40 -0.01%
slim-resnet50v2 64 3,340.59 3,328.69 0.36%
bert-mrpc-onnx 8 1,147.88 1,149.05 -0.10%
bert-mrpc-tf 1 309.56 308.98 0.19%
pytorch-examples-wlang-gru 1 433.92 416.23 4.25% 🔆
pytorch-examples-wlang-lstm 1 455.59 374.95 21.51% 🔆
torchvision-resnet50_1 1 807.35 799.37 1.00%
cadene-dpn92_1 1 396.39 432.81 -8.41% 🔴
cadene-resnext101_1 1 376.53 378.19 -0.44%
onnx-taau-downsample 1 344.18 345.37 -0.34%
dlrm-criteoterabyte 1 35.03 35.05 -0.05%
dlrm-criteoterabyte_fp16 1 57.32 57.40 -0.14%
agentmodel 1 7,860.89 9,772.50 -19.56% 🔴
unet_fp16 2 57.76 57.79 -0.05%
resnet50v1_fp16 1 931.66 939.67 -0.85%
resnet50v1_int8 1 981.22 929.28 5.59% 🔆
bert_base_cased_fp16 64 1,141.98 1,142.07 -0.01%
bert_large_uncased_fp16 32 351.81 351.79 0.01%
bert_large_fp16 1 208.66 209.75 -0.52%
distilgpt2_fp16 16 2,152.42 2,151.98 0.02%
yolov5s 1 504.54 506.15 -0.32%
tinyllama 1 43.46 43.34 0.26%
vicuna-fastchat 1 170.39 169.35 0.61%
whisper-tiny-encoder 1 410.36 411.82 -0.36%
whisper-tiny-decoder 1 419.44 429.16 -2.26%

This build is not recommended to merge 🔴

@migraphx-bot
Copy link
Collaborator


     ✅ bert-mrpc-onnx: PASSED: MIGraphX meets tolerance

     ✅ bert-mrpc-tf: PASSED: MIGraphX meets tolerance

     ✅ pytorch-examples-wlang-gru: PASSED: MIGraphX meets tolerance

     ✅ pytorch-examples-wlang-lstm: PASSED: MIGraphX meets tolerance

     ✅ torchvision-resnet50_1: PASSED: MIGraphX meets tolerance

     ✅ cadene-dpn92_1: PASSED: MIGraphX meets tolerance

     ✅ cadene-resnext101_1: PASSED: MIGraphX meets tolerance

     ✅ dlrm-criteoterabyte: PASSED: MIGraphX meets tolerance

     ✅ agentmodel: PASSED: MIGraphX meets tolerance

     ✅ unet: PASSED: MIGraphX meets tolerance

     ✅ resnet50v1: PASSED: MIGraphX meets tolerance

     ✅ bert_base_cased_fp16: PASSED: MIGraphX meets tolerance

🔴bert_large_uncased_fp16: FAILED: MIGraphX is not within tolerance - check verbose output


     ✅ bert_large: PASSED: MIGraphX meets tolerance

     ✅ yolov5s: PASSED: MIGraphX meets tolerance

     ✅ tinyllama: PASSED: MIGraphX meets tolerance

     ✅ vicuna-fastchat: PASSED: MIGraphX meets tolerance

     ✅ whisper-tiny-encoder: PASSED: MIGraphX meets tolerance

     ✅ whisper-tiny-decoder: PASSED: MIGraphX meets tolerance

     ✅ distilgpt2_fp16: PASSED: MIGraphX meets tolerance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants